package com.sumainfor.pc.gmio.service.impl;
import com.sumainfor.common.util.ContextUtils;
import com.sumainfor.common.util.JsonResult;
import com.sumainfor.common.utlis.ParamsCommon;
import com.sumainfor.pc.gmio.dao.SeOverflowMapper;
import com.sumainfor.pc.gmio.dao.SePaymentHistoryMapper;
import com.sumainfor.pc.gmio.service.SeOverflowService;
import com.sumainfor.pc.gmio.service.SePaymentHistoryService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.locks.ReentrantLock;

/**
 * 服务秘书 水电账单溢出
 */
@Service
public class SeOverflowSerivceImpl implements SeOverflowService {

    private ReentrantLock lock = new ReentrantLock(false);
    Logger log= LoggerFactory.getLogger(SeOverflowSerivceImpl.class);
    @Autowired
    private SeOverflowMapper seOverflowMapper;

    /**
     * 查询账单的溢出信息
     */
    @Override
    public Map<String, Object> getOverflowBySouId(Map<String, Object> params) {
        return seOverflowMapper.getOverflowBySouId(params);
    }
    /**
     * 服务秘书审核账单的时候根据租客编号查询账单的溢出信息
     */
    @Override
    public JsonResult getSeOverflowList(Map<String, Object> params) {
        JsonResult result=new JsonResult();
        if(params.get("TenId")==null){
            return result.putFailed("参数不正确");
        }
        List<Map<String,Object>> list=seOverflowMapper.getSeOverflowList(params);
        if (list!=null){
            result.put(list);
        }else{
            result.putFailed("服务器繁忙");
        }
        return result;
    }
    /**
     * 服务秘书审核账单的时候选择是否抵扣
     */
    @Override
    public JsonResult updateSeDeduction(Map<String, Object> params) {
        JsonResult result=new JsonResult();
        if(params.get("oveIdList")==null){
            return result.putFailed("参数不正确");
        }
        //组装修改参数
        Map<String,Object> updateMap=new HashMap<String,Object>();
        updateMap.put("Deduction","1");//是否抵扣   0未抵扣  1抵扣
        updateMap.put("by",ContextUtils.getUserId());//操作人
        updateMap.put("term", "4");// 创建端 Insert端： 1 租客端 2市场部 3 工程部   4运营部   5财务部  6总经办 7发展部
        updateMap.put("fnc",
                this.getClass().getSimpleName() + "." + Thread.currentThread().getStackTrace()[1].getMethodName());// 创建Function名
        ParamsCommon.commonInsertParms(updateMap);
        List<Map<String,Object>> list=(List<Map<String,Object>>)params.get("oveIdList");
        for (Map<String,Object> map:list){
            map.putAll(updateMap);
        }
        Integer count=seOverflowMapper.updateSeDeduction(params);
        if (count!=null && count>0){
            result.putSuccess("操作成功");
        }else{
            result.putFailed("服务器繁忙");
        }
        return result;
    }
}
